<template>
  <div class="message" @scroll="gun" ref="gunju">
     <div class="top">
          <img src="../assets/返回.png" alt="" @click="fanhui">
        </div>
      <div class="vid">
        <video autoplay="autoplay" :src="video" width="100%"  height="100%" controls>
        </video>
      </div>
      <van-popup v-model="show" position="bottom" :style="{ height: '30%' }" />

      <van-tabs v-model="activeName" class="vantabs"  @click="tiaoping(activeName)">
         <router-view></router-view>
         <van-tab  title="简介" name="jianjie">

          <div class="centent" v-for="(item,index) in content" :key="index">
          <p>{{item.title}}</p>

          <div class="centent-title">
              <p class="p1">{{item.categories[0].category_name}}-{{item.categories[0].sub.category_name}}</p>
              <p class="p1">{{kann[0]}}次播放</p>
          </div>

          <div class="centent-text">
              <p class="p2">{{item.content}}</p>
          </div>

          <div class="centent-icon">
              <div class="icon-item">
                <img src="../assets/点赞黑.png" alt="">
                <p class="pp">{{zann[0]}}</p>
              </div>
               <div class="icon-item">
                <img src="../assets/星星 .png" alt="">
                <p class="pp">{{cang}}</p>
              </div>
               <div class="icon-item">
                <img src="../assets/分享.png" alt="">
                <p class="pp">{{xiang}}</p>
              </div>
          </div>

          <div class="centent-bottom" >
             <div class="item" v-for="(item,index) in title" :key="index">{{item.name}}</div>
          </div>

          <div class="author">
              <p class="author-p">创作人</p>
              <div class="author-text">
                <div class="author-content">

                   <div class="author-item">
                       <img class="im1" :src="item.author.userinfo.avatar" alt="" @click="tiao(item.author.userinfo.id)">
                       <div class="author-name"  @click="tiao(item.author.userinfo.id)">
                           <span class="sp1">{{item.author.userinfo.username}}</span>
                           <img  class="im2" v-if="item.author.userinfo.vip_status===1" src="../assets/vip.png" alt="">
                           <span class="sp2">{{item.author.role}}</span>
                       </div>
                       <div class="guanzhu" :style="Guanstyle" @click="guan(item.author.userinfo.id)">{{guanzhu}}</div>
                   </div>
                
                </div>
              </div>
          </div>

        <div class="xiangsi">
           <p class="sip">{{sititle}}</p>
           <div class="sicentent" v-for="(item,index) in xiangsivideo" :key="index" @click="xiangsi(item.id)">
               <img  :src="item.cover" alt="">
               <div class="centent-left">
                   <p class="p5">{{item.title}}</p>
                   <p class="p6">播放&nbsp;{{bofang[index]}}&nbsp;&nbsp;喜欢&nbsp;{{xihuan[index]}}</p>
                   <div class="authord">
                    <img class="imgauthor" :src="item.author.userinfo.avatar" alt="">
                   <span>{{item.author.userinfo.username}}</span>
                   </div>   
               </div>
           </div>
       </div>

       </div>
         </van-tab>
         <van-tab  title="评论" name="pinglun">
           <div class="pingcentent" v-for="(item,index) in pinglun" :key="index">
            <img :src="item.userInfo.avatar" alt="" @click="go(item.userInfo.id)">

       <div class="author">
         <div class="author-top">
            <span>{{item.userInfo.username}}</span>
            <img v-if="item.userInfo.vip_status===1" src="../assets/vip.png" alt="">
                 </div>
                 <p class="p1" style="white-space:pre-wrap">{{item.content}}</p>
                 <p class="p2">{{date[index]}}</p>
               </div>
        
               <div class="img">
                 <img class="tu1" src="../assets/评论小.png" alt="">
                 <img class="tu2" src="../assets/点赞黑.png" alt="">
                 <span>0</span>
               </div>
               </div>
         </van-tab>
      </van-tabs>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
    created(){
      let ar = JSON.parse(localStorage.getItem("userid"));
      
      if(ar != null){
        if(ar.indexOf(localStorage.getItem("userid"))==-1){
            for(let i = 0;i < ar.length; i++){
              this.authorid.unshift(ar[i]);
          }
        }
      }
      
      this.getmessage(this.$route.query.id)
      this.getauthor(this.$route.query.id)
      this.getauthorleisi(this.$route.query.id)

      let biao=JSON.parse(localStorage.getItem('biaoji'))
     
      if(biao===true){
        this.guanzhu="取消关注"
         this.Guanstyle.backgroundColor="#ddd"
         this.Guanstyle.color="white"
         this.sestid=false
      }
    },
    data(){
      return{
        ids:31,
        video:"",
        videowidth:'',
        videoheight:'',
        show: false,
         activeName: '1',
        id:'',

         content:[],
         //播放次数
         kann:[],
         //喜欢
         zann:[],
         //收藏
         cang:'',
         //分享
         xiang:'',
         //标题
         title:[],
         sititle:'',
         xiangsivideo:[],
         //推荐视频的播放
         bofang:[],
         //推荐视频的喜欢
         xihuan:[],
         id:'',
         //存储要关注用户的id
         authorid:[],
         //关注
         guanzhu:'关注',
         Guanstyle:{
              backgroundColor: 'rgb(250,237,231)',
              color: 'rgb(231,104,93)'
         },
         arr:[],

          page:1,
          pinglun:[],
          date:[],

          shipinid:'',

          sestid:true
      }
  },
  methods:{
    go(id){
      this.$router.push({name:'author',query:{id:id}})
    },
    gun(){
      
       
    },
    tiao(id){
     
      this.$router.push({name:'author',query:{id:id}})
      
    },
    // showPopup() {
    //   this.show = true;
    // },
    //点击评论跳转
    tiaoping(name){
      if(name==="pinglun"){
        
        this.getpinglun(this.$route.query.id)
      }
    },

      //关注
      guan(userid){
        
        if(this.sestid===true){
          localStorage.setItem('biaoji',this.sestid)
         this.guanzhu="取消关注"
         this.Guanstyle.backgroundColor="#ddd"
         this.Guanstyle.color="white"
         this.myguanzhu(userid)
         this.sestid=false
        }else{
          localStorage.setItem('biaoji',this.sestid)
          this.guanzhu="关注"
          this.Guanstyle.backgroundColor="rgb(250,237,231)"
          this.Guanstyle.color="rgb(231,104,93)"
          this.quxiao(userid)
          this.sestid=true
        }


       
        
      },
       //关注设置本地存储用户的id
      myguanzhu(id){
         id=String(id)
         let isLogin = JSON.parse(localStorage.getItem("toke"));
         
          if(isLogin===null){
                Toast("请先登录")
                this.$router.push({name:'Login'})
          }
          if(isLogin!=null){
              this.authorid.unshift(id)
              localStorage.setItem('userid',JSON.stringify(this.authorid))
          }
        
      },
      //取消关注
      quxiao(id){
        id=String(id)
        let isLogin = JSON.parse(localStorage.getItem("toke"));
        if(isLogin!=null){
              this.authorid.pop(id)
              localStorage.setItem('userid',JSON.stringify(this.authorid))
        }
      },
      //返回上一级
      fanhui(){
        this.$router.go(-1)
      },

      getmessage(id){
          this.axios({
              method:'get',
              url:'https://apis.netstart.cn/xpc/article/'+id
              
          }).then(result=>{
             
              this.video=result.data.data.video.content.progressive[0].url
              this.shipinid=result.data.data.video.content.progressive[0].id
              
              //  this.$router.push({name:name,query:{id:id}})
          }).catch(err=>{
            
          })
      },
      //简介
      getauthor(id){
          this.axios({
              method:'get',
              url:'https://apis.netstart.cn/xpc/article/'+id
          }).then(result=>{
              this.content.push(result.data.data)
         
              this.title=this.content[0].tags
              this.content.forEach(v => {
                  let kan=this.formatNumber(v.count.count_view)
                  let zan=this.formatNumber(v.count.count_like)
                  let cang=this.formatNumber(v.count.count_collect)
                  let xiang=this.formatNumber(v.count.count_share)
                  this.cang=cang
                  this.xiang=xiang
                  this.kann.push(kan)
                  this.zann.push(zan)
              });
              
          }).catch(err=>{
            
          })
      },

      //相似视频
      getauthorleisi(id){
         this.axios({
             method:'get',
             url:'https://apis.netstart.cn/xpc/article/'+id+'/next'
         }).then(result=>{
             
             this.sititle=result.data.data.title
             this.xiangsivideo=result.data.data.list
             this.xiangsivideo.forEach(v=>{
                let bofang=this.formatNumber(v.count.count_view)
                let xihuan=this.formatNumber(v.count.count_like)
                this.bofang.push(bofang)
                this.xihuan.push(xihuan)
                
             })
            
         }).catch(err=>{
            
         })
      },
      
        //视频详情页
      xiangsi(id){
          
          this.$router.push({name:'message',query:{id:id}})
          this.$router.go(0)
      },
       //视频点赞数
       formatNumber(num) {
      num = Number(num);
      if (num == 0) {
        return num + "";
      } else if (num >= 1 && num <= 10000) {
        return num + "";
      } else {
        return (num / 10000).toFixed(1) + "w";
      }
      },

      getpinglun(id){
       this.axios({
         method:'get',
         url:'https://apis.netstart.cn/xpc/comments?&type=article&page=2',
         params:{
           resource_id:id,
         }
       }).then(result=>{
         this.pinglun=result.data.data.list
         
         this.pinglun.forEach(v=> {
            let date=new Date(v.addtime*1000)
            this.date.push(date.toLocaleString().substring(0,9).replaceAll("/","-"))
         });
       }).catch(err=>{
         
       })
    }
  },
  
}
</script>

<style lang="less" scoped>
.message{
    width: 100%;
    height: 100%;
}
 video{
    width: 100%;
    height: 220px;
    
}
.top{
      width: 100%;
      display: flex;
      position: fixed;
      top:15px;
      z-index: 999;
      justify-content: space-between;
     img:nth-child(1){
        width: 20px;
        height: 20px;
        margin-left: 15px;
        
     }
     img:nth-child(2){
        width: 20px;
        height: 20px;
        position: relative;
        margin-right: 20px;
        
     }
    }
.vantabs{
    width: 100%;
    height: 40px;
    border-bottom: 5px solid #ddd;
}

.jianjie{
    width: 94%;
    padding: 10px;
    height: calc(100vh -264px);
    overflow-y: auto;
}
.centent{
    width: 100%;
    margin-top: -10px;
    p{
      width: 95%;
      margin-left: 10px;
      letter-spacing: 1px;
      font-size: 20px;
      font-weight: bold;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      overflow: hidden;
    }
    .centent-title{
        width: 70%;
        height: 30px;
       display: flex;
       margin-top: -10px;
       justify-content: space-between;
       .p1{
           height: 20px;
           margin-top: 0px;
           font-size: 13px;
           font-weight: 500;
           color: rgb(158, 157, 157);
           letter-spacing: 0px;
       }
    }
    .centent-text{
        width: 100%;
        margin-top: -15px;
        .p2{
            width: 95%;
            font-weight: 600;
            font-weight: 500;
            letter-spacing: 0px;
            font-size: 14px;
            color: rgb(138, 136, 136);
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: hidden;
        }
    }
    .centent-icon{
        width: 100%;
        height: 25px;
        display: flex;
        text-align: center;
        justify-content: space-between;
        .icon-item{
           width: 33%;
           height: 40px;
           text-align: center;
           
           img{
               width: 20px;
               height: 20px;
           }
           .pp{
               letter-spacing: 0px;
               display: flex;
               justify-content: center;
               width: 50%;
               margin-top: 0px;
               margin-left: 25%;
               font-size: 13px;
           }
        }
    
    }
    .centent-bottom{
        width: 100%;
        height: 80px;
        margin-top: 25px;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        .item{
            padding: 5px;
            height: 20px;
            font-size: 12px;
            border-radius: 5px;
            margin-left: 15px;
            text-align: center;
            line-height: 20px;
            color: black;
            background-color: rgb(239, 237, 237);
        }
      
    }
    .author{
        width: 100%;
        height: 130px;
        .author-p{
           font-size: 18px;
           
        }
        .author-text{
            width: 100%;
            height: 70px;
           
            .author-content{
               height: 70px;
               white-space: nowrap;
               
               .author-item{
                   width: 250px;
                   height: 70px;
                   display: flex;
                   display: inline-block;
                   border-radius: 10px;
                   border: 1px solid #ddd;
                   padding: 0px 10px;
                   margin-left: 15px;
                   align-items: center;
                   box-shadow: 0px 0px 20px 0px #ddd;
                .im1{
                   width: 45px;
                   height: 45px;
                   border-radius: 50%;
                   margin-top: 10px;
                   border: 1px solid #ddd;
                }
                .author-name{
                    width: 45%;
                    height: 45px;
                    display: flex;
                    flex-wrap: wrap;
                    margin-top: -45px;
                    margin-left: 55px;
                    .sp1{
                        font-size: 13px;
                        letter-spacing: 1px;
                        font-weight: bold;
                        text-overflow: ellipsis;
                       display: -webkit-box;
                       -webkit-box-orient: vertical;
                       -webkit-line-clamp: 1;
                       overflow: hidden;
            
                    }
                    .im2{
                        width: 20px;
                        height: 20px;
                        margin-left: 5px;
                    }
                    .sp2{
                        width: 90%;
                        height: 20px;
                        font-size: 11px;
                        margin-top: 5px;
                        color: rgb(149, 145, 145);
                        text-overflow: ellipsis;
                       display: -webkit-box;
                       -webkit-box-orient: vertical;
                       -webkit-line-clamp: 1;
                       overflow: hidden;
                    }
                }
                .guanzhu{
                    margin-top: -40px;
                    margin-left:70%;
                    width: 70px;
                    height: 30px;
                    border-radius: 10px;
                    text-align: center;
                    line-height: 30px;
                    
                    
                    
                }
               }
            }
        }
    }
}
.xiangsi{
    width: 100%;
    .sip{
    width: 100%;
    height: 30px;
    font-size: 20px;
    font-weight: bold;
    margin-left: 10px;
    }
    .sicentent{
        width: 100%;
        height: 110px;
        display: flex;
        margin-top: 20px;
        margin-bottom: 20px;
        img{
            width: 180px;
            height: 110px;
            border-radius: 10px;
        }
        .centent-left{
            width: 50%;
            height: 100px;
            .p5{
               text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 1;
              overflow: hidden;
              font-size: 15px;
            }
            .p6{
                margin-top: -3px;
                font-size: 12px;
                font-weight: 500;
                color: rgb(172, 168, 168);
            }
            .authord{
                display: flex;
                align-items: center;
                margin-top: -5px;
            }
            .imgauthor{
                width: 25px;
                height: 25px;
                border-radius: 50%;
                border: 1px solid #ddd;
                margin-left: 10px;
                margin-top: 0px;
            }
            span{
                margin-top: 0px;
                margin-left: 10px;
            }
        }
    }
   
}

.pingcentent{
  width: 100%;
  height: 100px;
  display: flex;
  border-bottom: 1px solid #ddd;
  img{
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 1px solid #ddd;
    margin-left: 10px;
    margin-top: 10px;
  }
  .author{
    width: 250px;
    height: 90px;
    margin-left: 10px;
  
    .author-top{
      width: 200px;
      height: 30px;
      display: flex;
      align-items: center;
      span{
        font-size: 12px;
      }
      img{
      width: 20px;
      height: 20px;
      margin-top: -3px;
      margin-left: 0px;
      }
    }
    .p1{
      margin-top: 0px;
      font-size: 14px;
       text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    }
  }
  .img{
    width: 70px;
    height: 30px;
    display: flex;
    align-items: center;
    margin-top: 50px;
    
    .tu1{
      border-radius: 0%;
      border: 1px solid transparent;
      width: 15px;
      height: 15px;
      margin-left: 0px;
    }
    .tu2{
      border-radius: 0%;
      border: 1px solid transparent;
      width: 18px;
      height: 18px;
      margin-left:16px;
    }
    span{
      margin-left: 0px;
      margin-top: 13px;
    }
  }
}
</style>